/*
 * @Author: song
 * @Description: 声音轨道绘制
 * @Date: 2024年04月28日 星期日 20:04:04
 * @Modify:
 */

using Function.SkillEditor.Runtime;
using SCore.Editor.WindowDraw;
using SCore.Function.Fixed;
using SCore.Editor;
using UnityEditor;
using UnityEngine;

namespace Function.SkillEditor.Editor
{
    public class SkillAnimatorClipDraw : ISkillClipDrawer
    {
        public override void OnInspector(Rect rect)
        {
            base.OnInspector(rect);
            EditorGUI.BeginChangeCheck();
            var animationClip =
                EditorDrawHelp.DrawHObjetField(new Rect(rect.x, GetInspectorHeight(rect), rect.width, 20),
                    "Object", _skillClip._asset as AnimationClip);
            if (EditorGUI.EndChangeCheck())
            {
                _skillClip._asset = animationClip;
            }
        }

        public override void OnProgress(bool isPlay, fp progress)
        {
            fp curPlayerTime =
                progress - _skillClip._startFrame * SkillRunMap.Instance.GetEOneFrameTime();
            (_skillClip._asset as AnimationClip)?.SampleAnimation(SkillTimeLineSubWindow._editorGo,
                curPlayerTime.AsFloat());
        }
    }


    [TrackDrawEditor(typeof(SkillAnimatorTrack), typeof(SkillAnimatorClipDraw))]
    public class SkillAnimatorTrackDraw : ISkillTrackDrawer<SkillAnimatorTrack>
    {
        public SkillAnimatorTrackDraw(SkillAnimatorTrack skillTrack, TrackRegisterAttribute trackRegister) : base(
            skillTrack, trackRegister)
        {
        }

        protected override void DrawGroup()
        {
            EditorGUI.LabelField(new Rect(_headRect.x + 10, _headRect.y, _headRect.width, _headRect.height), "Anim");
        }

        protected override void OnTimeLinePlayStatusChange(bool play)
        {
            EditorAudioUtil.StopAllPreviewClips();
            base.OnTimeLinePlayStatusChange(play);
        }
    }
}